package View.MaintainPage.gChange;


import View.MaintainPage.gMain.Mainweihu;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.stage.Stage;
import sx.dao.GoodsDao;
import sx.entity.Goods;

public class Mainchange extends Application {
	
	  @FXML
	    private TextField nnew;

	    @FXML
	    private Label resultshow;

	    @FXML
	    private Button newsum;

	    @FXML
	    private Button endButton;

	    @FXML
	    private Button newname;

	    @FXML
	    private Button newprice;

	    @FXML
	    private TextField cid;

	    @FXML
	    void act1(ActionEvent event) {
	    	int ket=1;
	    	int gid=Integer.parseInt(cid.getText());
	    	String gname=nnew.getText();
	    	Goods goodsname=new Goods(gid, gname);
	    	GoodsDao daoname=new GoodsDao();
	    	daoname.updateGoods(ket, goodsname);
	    }

	    @FXML
	    void act2(ActionEvent event) {
	    	int key=2;
	    	int gid=Integer.parseInt(cid.getText());
	    	double gprice=Double.parseDouble(nnew.getText());
	    	Goods goodsprice=new Goods(gid, gprice);
	    	GoodsDao daoprice=new GoodsDao();
	    	daoprice.updateGoods(key, goodsprice);
	    }

	    @FXML
	    void act3(ActionEvent event) {
	    	int key=3;
	    	int gid=Integer.parseInt(cid.getText());
	    	int gsum=Integer.parseInt(nnew.getText());
	    	Goods goodssum=new Goods(gid, gsum);
	    	GoodsDao daosum=new GoodsDao();
	    	daosum.updateGoods(key, goodssum);
	    }

	

	@FXML    
    void Rback3(ActionEvent event) {
    	try {
			 new Mainweihu().start(new Stage());//??????????
			 
		} catch (Exception e) {
			// TODO: handle exception
		}
    	exitButtonOnMouseClicked(endButton);
    }
	//??????????????
    //exitButton???????????????
    public void exitButtonOnMouseClicked(Button exitButton) {
        Stage stage = (Stage)exitButton.getScene().getWindow();
        stage.close();
    }
	@Override
	public void start(Stage primaryStage) {

		try {
			Class clazz = getClass();
			Parent root = FXMLLoader.load(clazz.getResource("Mainchange.fxml"));
			Scene scene = new Scene(root, 600, 600);
			scene.getStylesheets().add(getClass().getResource("/sources/Css/application1.css").toExternalForm());
			primaryStage.setScene(scene);
			primaryStage.show();
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	public static void main(String[] args) {
		launch(args);
	}

}
